{# Template for up/down vote arrows.
 # This template expects these inputs
 # 
 #     - target: ('post', 'comment')
 #     - item: either a "post" object or a "comment"
 #     - user: reference to logged in user
 #}

{% macro vote (target, item, user) %}

    <span class="vote {{ 'upvoted' if item.user_vote == 1 else '' }} {{ 'downvoted' if item.user_vote == -1 else '' }}">

        {% if user %}
            
            <form action="{{ url ('vote') }}" target="vote_sink" method="post">
                <input type="hidden" name="target" value="{{ target }}" />
                <input type="hidden" name="{{ target }}" value="{{ item.hashId }}" />
                <input type="hidden" name="updown" value="up" />
                
                <button title="upvote" class="">
                    <img src="{{ url ('static', filename='images/upvote.png') }}" />
                </button>
            </form>
            
            {# Show number of votes #}
            <span class="count">{{ item.vote }}</span>
            
            <form action="{{ url ('vote') }}" target="vote_sink" method="post">
                <input type="hidden" name="target" value="{{ target }}" />
                <input type="hidden" name="{{ target }}" value="{{ item.hashId }}" />
                <input type="hidden" name="updown" value="down" />
                
                <button title="downvote" class="">
                    <img src="{{ url ('static', filename='images/downvote.png') }}" />
                </button>
            </form>
        
        {% else %}
            
            {{ item.vote ~ ' vote' ~ ('s' if item.vote != 1) }}
            
        {% endif %}
        
    </span>

{% endmacro %}
